home *** CD-ROM | disk | FTP | other *** search
- //******************************************************************'
- //* *'
- //* TurboCAD for Windows *'
- //* Copyright (c) 1993 - 2004 *'
- //* International Microcomputer Software, Inc. *'
- //* (IMSI) *'
- //* All rights reserved. *'
- //* *'
- //******************************************************************'
-
- using System;
- using System.Windows.Forms;
- using IMSIGX;
- namespace TCGeometry
- {
- /// <summary>
- /// Summary description for TCengine.
- /// </summary>
- public class TCengine
- {
- public IMSIGX.XApplication m_gxApp;
- public IMSIGX.IDrawing m_gxDrawing;
- public IMSIGX.View m_gxView;
-
- public TCengine()
- {
- //
- // TODO: Add constructor logic here
- m_gxApp = null;
- m_gxDrawing = null;
- m_gxView = null;
- //
- }
-
- /// <summary>
- /// Creates imsigx application object
- /// </summary>
- public void CreategxApp()
- {
- try
- {
- if (m_gxApp == null)
- {
- m_gxApp = new IMSIGX.XApplication();
- }
- }
- catch(System.Exception exc)
- {
- Console.WriteLine("{0} Caught exception .", exc);
- }
-
-
-
- }
- public void CreateNewDrawing()
- {
- object missing = null;
-
- try
- {
- if (m_gxApp == null)
- {
- CreategxApp();
- }
- if (m_gxDrawing != null)
- {
- MessageBox.Show ("Drawing is already created !");
- }
- else
- {
- m_gxDrawing = m_gxApp.Drawings.Add(ref missing);
- }
- }
-
-
-
- catch(System.Exception exc)
- {
- Console.WriteLine("{0} Caught exception .", exc);
- }
-
- }
- public void CreategxView(int hWnd)
- {
- object missing = null;
- object h;
- try
- {
- h = hWnd;
- if (m_gxDrawing != null)
- {
- m_gxView = m_gxDrawing.Views.Add ( ref h, ref missing);
- m_gxView.Update = false;
- m_gxView.MappingMode = 1;
- m_gxView.FixedAspectRatio = true;
- }
- }
-
- catch(System.Exception exc)
- {
- Console.WriteLine("{0} Caught exception .", exc);
- }
-
- }
- public IMSIGX.IGraphic AddLineSingle(double x1Screen, double y1Screen, double x2Screen, double y2Screen)
- {
- double x1View, y1View, x2View, y2View, zView;
- double x1World, y1World, x2World, y2World;
- zView = 0;
- IMSIGX.IGraphic grRet;
-
- this.m_gxView.ScreenToView (x1Screen, y1Screen, out x1View, out y1View);
- this.m_gxView.ScreenToView (x2Screen, y2Screen,out x2View, out y2View);
- this.m_gxView.ViewToWorld (x1View, y1View,zView, out x1World, out y1World, out zView);
- this.m_gxView.ViewToWorld (x2View, y2View, zView, out x2World, out y2World, out zView);
-
- grRet = this.m_gxDrawing.Graphics.AddLineSingle (x1World,y1World,0,x2World,y2World,0);
- return grRet;
- }
- public IMSIGX.IGraphic AddCircleCenterAndPoint(double x1Screen, double y1Screen, double x2Screen, double y2Screen)
- {
- double x1View, y1View, x2View, y2View, zView;
- double x1World, y1World, x2World, y2World;
- zView = 0;
- IMSIGX.IGraphic grRet;
-
- this.m_gxView.ScreenToView (x1Screen, y1Screen, out x1View, out y1View);
- this.m_gxView.ScreenToView (x2Screen, y2Screen,out x2View, out y2View);
- this.m_gxView.ViewToWorld (x1View, y1View,zView, out x1World, out y1World, out zView);
- this.m_gxView.ViewToWorld (x2View, y2View, zView, out x2World, out y2World, out zView);
-
- grRet = this.m_gxDrawing.Graphics.AddCircleCenterAndPoint (x1World,y1World,0,x2World,y2World,0);
- return grRet;
- }
-
- public IMSIGX.IGraphic SelectGraphic(double xScreen, double yScreen)
- {
- double xView, yView;
- object varVal;
- object missing = null;
- IMSIGX.PickResult gxPickResult;
- IMSIGX.PickEntry gxPickEntry;
- IMSIGX.IGraphic gxvarGraphic = null;
- this.m_gxView.ScreenToView (xScreen, yScreen, out xView, out yView);
- gxPickResult = this.m_gxView.PickPoint (xView, yView,ref missing,ref missing, ref missing, ref missing,ref missing, ref missing,ref missing);
- if (gxPickResult.Count != 0 )
- {
- varVal = 0;
- gxPickEntry = gxPickResult.get_Item(ref varVal);
- gxvarGraphic = gxPickEntry.Graphic;
- }
- else
- {
- this.m_gxDrawing.Graphics.Unselect ();
- }
- return gxvarGraphic;
- }
-
- public void Zoom(double zoomfactor)
- {
-
- if (zoomfactor != 0)
- {
- try
- {
- this.m_gxView.Camera.Zoom (zoomfactor);
- }
- catch // in case of paper space (not possible to get camera object in paperSpace) or unexpected error in model space
- {
- double xC = 0; double yC = 0;
- double w = 0; double h = 0;
-
- //On Error GoTo Err
- w = this.m_gxView.ViewWidth;
- h = this.m_gxView.ViewHeight;
-
- xC = this.m_gxView.ViewLeft + w / 2;
- yC = this.m_gxView.ViewTop - h / 2;
- w = w * zoomfactor;
- h = h * zoomfactor;
- this.m_gxView.Update = false;
-
- this.m_gxView.ViewLeft = xC - w / 2;
- this.m_gxView.ViewTop = yC + h / 2;
- this.m_gxView.ViewWidth = w;
- this.m_gxView.ViewHeight = h;
- }
- }
- else
- {
- this.m_gxView.ZoomToExtents ();
- }
- }
-
- }
- }
-